<form class="layui-form layui-form-pane edit-form">
    <div class="layui-form-item">
        <label class="layui-form-label">
            商品名称
        </label>
        <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" name="title" type="text" value="{$data['title']}"/>
        </div>
    </div>
  
    <div class="layui-form-item">
        <label class="layui-form-label">
           会员价
        </label>
        <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" name="price" type="number" value="{$data['price']}"/>
        </div>
    </div>

        <div class="layui-form-item">
        <label class="layui-form-label">
            原价
        </label>
        <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" name="price1" type="number" value="{$data['price1']}"/>
        </div>
    </div>
     <div class="layui-form-item">
       
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
 
        </fieldset>
        <div class="layui-upload">
          <button type="button" class="layui-btn" id="test2">轮播图</button> 
          <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
            预览图：
            <div class="layui-upload-list" id="demo2">
                {if $data['banner']!==''}
                {foreach $data['banner'] as $key =>$v}
                    <div style="position:relative; margin-right:10px; display:inline-block;"><span id="del" style="position: absolute; right: 0; top: 0; width: 20px; height: 20px; cursor: pointer; text-align: center; font-size: 18px; color: #fff; background: rgba(0,0,0,.5); line-height: 20px;" data-src='{$v}'>×</span><img style="max-width:200px;max-height:200px" src='{$v}'  class='layui-upload-img'></div>
                    <input name="banner[]" type='hidden' value="{$v}">
                {/foreach}
                {/if}
            </div>
         </blockquote>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            权重
        </label>
        <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" name="sort" type="text" value="{$data['sort']}"/>
        </div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label">
            库存
        </label>
        <div class="layui-input-block">
            <input autocomplete="off" class="layui-input" name="surplus_num" type="number" value="{$data['surplus_num']}"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            精选商品
        </label>
        <div class="layui-input-block">
             <select name="hot"  id='hot' lay-search lay-filter="hot"> 
                
                <option {if $data['hot'] ==0}selected{/if} value=0>否</option>
                <option {if $data['hot'] ==1}selected{/if} value=1>是</option>
               
            </select>   
        </div>
    </div> 

    <div class="layui-form-item">
        <label class="layui-form-label">
            商品分类
        </label>
        <div class="layui-input-block">
             <select name="goods_type"  id='goods_type' lay-search lay-filter="goods_type"> 
                {volist id='vo' name='type'}
                <option {if $data['goods_type'] ==$vo['id']}selected{/if} value={$vo.id}>{$vo.type}</option>
                {/volist}
               
            </select>   
        </div>
    </div> 
    <div class="layui-form-item">
        <label class="layui-form-label add_type">
            <i class="layui-icon layui-icon-add-1"></i>添加规格
        </label>
       
    </div>
     <div class="layui-form-item goods_type"> 
    {if isset($data['type'])}
    {foreach $data['type'] as $key =>$v}
   
        <div class="layui-input-block" style="margin-left: 0px!important">
            <input autocomplete="off" class="layui-input" name="type[]" type="text" value="{$v.type}" style="width: 60%;float: left" /><i class="layui-icon layui-icon-delete" data-id={$v.id} value="{$v.type}" style="float: left;margin-left: 10px;width: 20%;margin-top:10px"></i>
        </div>
    
    {/foreach}
    {/if}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label add_lable">
            <i class="layui-icon layui-icon-add-1"></i>添加标签
        </label>
       
    </div>
    <div class="layui-form-item goods_lable"> 
    {if isset($data['lable'])}
    {foreach $data['lable'] as $key =>$v}
   
        <div class="layui-input-block" style="margin-left: 0px!important">
            <input autocomplete="off" class="layui-input" name="lable[]" type="text" value="{$v.lable}" style="width: 60%;float: left" /><i class="layui-icon layui-icon-delete" data-id={$v.id} value="{$v.lable}" style="float: left;margin-left: 10px;width: 20%;margin-top:10px"></i>
        </div>
    
    {/foreach}
    {/if}
    </div>
<div class="layui-form-item">
            &nbsp;&nbsp;内容
        <hr class="layui-bg-cyan">
    </div>
    <textarea id="content" name="content" lay-verify="required" type="text/plain" style="width:100%;margin-bottom:20px;">{$data['content']}</textarea>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-filter="editform" lay-submit="">
                保存
            </button>
            <button class="layui-btn layui-btn-primary layui-btn-cancel" type="button">
                取消
            </button>
        </div>
    </div>
</form>
{load href="__plugin__/ueditor/ueditor.config.js,__plugin__/ueditor/ueditor.all.min.js" /}


<script type="text/javascript">
    var ue = UE.getEditor('content', {
        autoHeight: true,
        initialFrameHeight: 400,
        wordCount:false,
        maximumWords:1000000000000,
    });

    layui.use('upload', function(){
        var $ = layui.jquery,upload = layui.upload;
    //多图片上传
        upload.render({
            elem: '#test2'
            ,url: 'upload' //改成您自己的上传接口
            ,multiple: true
            ,before: function(obj){
              //预读本地文件示例，不支持ie8
              obj.preview(function(index, file, result){
                
              });
            }
            ,done: function(res){
                if(res.code == 1){
                    $('#demo2').append('<div style="position:relative; margin-right:10px; display:inline-block;"><span id="del" style="position: absolute; right: 0; top: 0; width: 20px; height: 20px; cursor: pointer; text-align: center; font-size: 18px; color: #fff; background: rgba(0,0,0,.5); line-height: 20px;" data-src="'+res.data+'">×</span><img style="max-width:200px;max-height:200px" src="'+ res.data +'"   class="layui-upload-img"></div> <input type="hidden" name="banner[]" value="'+res.data+'">');
                    
                }else{
                    layer.msg(res.msg);
                }
            }
        });   
    })

    $('.add_type').click(function(){
        $('.goods_type').append('<div class="layui-input-block" style="margin-left: 0px!important;margin-top:5px"><input autocomplete="off" class="layui-input" name="type[]" type="text" value="" style="width: 60%;float: left" /><i class="layui-icon layui-icon-delete" value=0 data-id=0 style="float: left;margin-left: 10px;width: 20%;margin-top:10px"></i></div>');
    })

    $('.add_lable').click(function(){
        $('.goods_lable').append('<div class="layui-input-block" style="margin-left: 0px!important;margin-top:5px"><input autocomplete="off" class="layui-input" name="lable[]" type="text" value="" style="width: 60%;float: left" /><i class="layui-icon layui-icon-delete" value=0 data-id=0 style="float: left;margin-left: 10px;width: 20%;margin-top:10px"></i></div>');
    })

 
    $('.goods_type').on('click','.layui-icon-delete',function(e){
        var id = $(this).attr('data-id');
        var _this = $(this);
        if(id != 0){
            _ajax({
                url:'removetype',    
                data:{'id':id},
                success:function(res){
                    if(res.code == 0){
                        layer.msg('删除失败');
                    }
                },
                error:function(){
                    layer.msg('请求失败，请稍后再试');
                }
            })
        }
        _this.parent().remove()
    })

    $('.goods_lable').on('click','.layui-icon-delete',function(e){
        var id = $(this).attr('data-id');
        var _this = $(this);
        if(id != 0){
            _ajax({
                url:'removelable',    
                data:{'id':id},
                success:function(res){
                    if(res.code == 0){
                        layer.msg('删除失败');
                    }
                },
                error:function(){
                    layer.msg('请求失败，请稍后再试');
                }
            })
        }
        _this.parent().remove()
    })

//重新渲染layui
    function renderForm(){
        layui.use('form', function(){
           var form = layui.form;
           form.render();
        });
    }    
    $(function(){    
        $('.layui-form-item').on('click','#del',function(){
            $(this).parent().next().remove();
                   $(this).parent().remove();
        })
    })    
  </script>